package com.suredy.tools;

import java.io.Serializable;
import java.util.List;

/**
 * 分页辅助类
 * 
 * @author VIVID.G
 * @since 2015-4-13
 * @version v0.1
 */
public class PageUtils implements Serializable {

	private final static long serialVersionUID = 5137172595020074456L;

	public final static int DEF_PAGE_SIZE = 10;

	private int page;
	private int pageSize = DEF_PAGE_SIZE;
	private int count;
	private List<?> data;

	private PageUtils(int page, int pageSize, int count, List<?> data) {
		this.page = page;
		this.count = count;
		this.data = data;
	}

	public int getPage() {
		return page;
	}

	public void setPage(int page) {
		this.page = page;
	}

	public int getPageSize() {
		return pageSize;
	}

	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}

	public int getCount() {
		return count;
	}

	public void setCount(int count) {
		this.count = count;
	}

	public List<?> getData() {
		return data;
	}

	public void setData(List<?> data) {
		this.data = data;
	}

	public int getPages() {
		int c = this.count / this.pageSize;

		if (this.count % this.pageSize != 0)
			c += 1;

		return c;
	}

	public boolean isFirst() {
		return this.page <= 1;
	}

	public boolean isLast() {
		return this.page >= this.getPages();
	}

	public final static PageUtils newPageInfo(int page, int count, List<?> data) {
		return new PageUtils(page, DEF_PAGE_SIZE, count, data);
	}

	public final static PageUtils newPageInfo(int page, int pageSize, int count, List<?> data) {
		return new PageUtils(page, pageSize, count, data);
	}

}
